<div class="amp-content">
  <h3 class="amp-header"><?php echo $action_title; ?></h3>

  <div class="amp-content">
    <div id="calendar"></div>

    <?php echo $this->html->css('../fullcalendar/fullcalendar') ?>
    <?php echo $this->javascript->link('../fullcalendar/fullcalendar') ?>
    <script>
    $(document).ready(function() {
      $('#calendar').fullCalendar({
        height:700,

        editable: true,
        
        header: {
          left:   'title',
          center: 'month, basicWeek, basicDay, agendaWeek, agendaDay',
          right:  'today prev,next'
        },

        dayClick: function(date, allDay, jsEvent, view) {
          window.location.href = '<?php echo s::response()->makeUrl($route, array('action' => 'create')) ?>';
        },

        eventDrop: function(event, dayDelta, minuteDelta, allDay, revertFunc) {
          var url = '<?php echo $response->makeUrl($route, array('action' => 'calendar')) ?>';
          var data = {
            formAction: 'calendar_update_event',
            id: event.id,
            start: event.start ? Math.round(event.start.getTime() / 1000) : 0,
            end: event.end ? Math.round(event.end.getTime() / 1000) : 0,
            allday: event.allDay
          }

          $.post(url, data, function(response) {
            alert(response);
          })
        },

        eventResize: function(event, dayDelta, minuteDelta, revertFunc, jsEvent, ui, view) {
          var url = '<?php echo $response->makeUrl($route, array('action' => 'calendar')) ?>';
          var data = {
            formAction: 'calendar_update_event',
            id: event.id,
            start: event.start ? Math.round(event.start.getTime() / 1000) : 0,
            end: event.end ? Math.round(event.end.getTime() / 1000) : 0,
            allday: event.allDay
          }

          $.post(url, data, function(response) {
            alert(response);
          })
        },

        eventSources: [{
          url: '<?php echo $response->makeUrl($route, array('action' => 'calendar')) ?>',
          type: 'POST',
          data: {
            formAction: 'calendar_get_events'
          },
          error: function() {
            alert('there was an error while fetching events!');
          }
        }]
      });
    });
    </script>
  </div>
</div>